package cn.wizzer.app.web.modules.controllers.platform.user.chat.redPacket;

import cn.wizzer.app.user.modules.services.RedPacketService;
import cn.wizzer.framework.page.Pagination;
import cn.wizzer.framework.util.Result;
import com.alibaba.dubbo.config.annotation.Reference;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.Param;

import java.math.BigDecimal;

@IocBean
@At("/platform/user/redPacket")
public class RedPacketController {

    @Inject
    @Reference
    private RedPacketService redPacketService;

    @At("/")
    @Ok("beetl:/platform/user/chat/redPacket/index.html")
    @RequiresPermissions("user.redPacket.list")
    public void index() {
    }


    @At
    @Ok("json:full")
    @RequiresPermissions("user.redPacket.list")
    public Object data(@Param("conditionData") String conditionData,
                       @Param("currencyId") String currencyId,
                       @Param("type") String type,
                       @Param("status") String status,
                       @Param("keyword") String keyword,
                       @Param("searchDate") String[] searchDate,
                       @Param("pageNumber") int pageNumber,
                       @Param("pageSize") int pageSize) {
        Pagination pagination = redPacketService.listPage(conditionData, currencyId, type, status, keyword, searchDate, pageNumber, pageSize);
        // 统计充值总额，根据搜索条件
        BigDecimal sum = redPacketService.searchSum(conditionData, currencyId, type, status, keyword, searchDate);
        return Result.success().addData(Result.createMap("pagination", pagination, "sum", sum));
    }
}
